Accusoft.ImagXpress13.Net
Reduce a PNG Image

Use the PngReduce method to losslessly reduce PNGs in memory or on disk without first decompressing to a DIB, thereby saving processor time and system resources. 

Supports 1, 4, 8, 16, and 24-bpp PNGs.

File size reduction is accomplished by removing select pieces of metadata and other possible color and/or transparency reductions of the source PNG.

Compression ratios will vary depending on the source PNG. For example, applying PngReduce to a 1280x960, 24-bit color PNG reduces its size from 1754 KB to 1377 KB. However, applying PngReduce to the reduced PNG results in no further size improvements.

To reduce PNGs on disk, just specify the path to the source PNG and the path to save the re-compressed PNG:

C# Example
Copy Code
try
{
    using (Accusoft.ImagXpressSdk.ImagXpress ix =
        new Accusoft.ImagXpressSdk.ImagXpress())
    {
        Accusoft.ImagXpressSdk.ImageReduce.PngReduce(
            ix, "OwlAlpha.png", "OwlAlpha.reduced.png");
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

The PngReduce method can use PNGs expressed in memory. First read the source PNG data into a byte array and then re-compress the PNG data:

C# Example
Copy Code
try
{
    // Read PNG file to a Byte array.
    String pngPath = "OwlAlpha.png";
    FileInfo fileInfo = new FileInfo(pngPath);
    Byte[] original = new Byte[fileInfo.Length];
    using (FileStream fileStream = new FileStream(
        pngPath, FileMode.Open, FileAccess.Read))
    {
        fileStream.Read(original, 0, (int)fileInfo.Length);
    }
    // Reduce PNG to a Byte array.
    Byte[] reduced;
    using (Accusoft.ImagXpressSdk.ImagXpress ix =
        new Accusoft.ImagXpressSdk.ImagXpress())
    {
        Accusoft.ImagXpressSdk.ImageReduce.PngReduce(
            ix, original, out reduced);
        Console.Write("Reduced \"{0}\" from {1} bytes to {2} bytes.",
            pngPath, original.Length, reduced.Length );
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

 

 


©2017. Accusoft Corporation. All Rights Reserved.

Send Feedback